import {
  selectAllHospitalType,
  allId,
  addHospitalType,
  updateHospitalType,
  deleteHospitalType
} from '@/api/hospitalType'


const getDefaultState = () => {
  return {}
}

const state = getDefaultState()

const mutations = {
  RESET_STATE: (state) => {
    Object.assign(state, getDefaultState())
  }
}


const actions = {

  selectAllHospitalType({
    commit
  }, hospitalTypeInfo) {
    return new Promise((resolve, reject) => {
      const {
        obj,
        page,
        pageSize
      } = hospitalTypeInfo
      selectAllHospitalType({
        obj: obj,
        page: page,
        pageSize: pageSize
      }).then(response => {
        resolve(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  allId({
    commit
  }, hospitalTypeInfo) {
    return new Promise((resolve, reject) => {
      const {
        name
      } = hospitalTypeInfo
      allId({
        name: name
      }).then(response => {
        resolve(response.data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  // use add hospitalType
  addHospitalType({
    commit
  }, hospitalTypeInfo) {
    return new Promise((resolve, reject) => {
      const {
        name
      } = hospitalTypeInfo
      addHospitalType({
        name: name
      }).then(response => {
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  },

  // use update role
  updateHospitalType({
    commit
  }, hospitalTypeInfo) {
    return new Promise((resolve, reject) => {
      const {
        hospitalTypeId,
        name
      } = hospitalTypeInfo
      updateHospitalType({
        hospitalTypeId: hospitalTypeId,
        name: name
      }).then(response => {
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  },

  // use delete HospitalType
  deleteHospitalType({
    commit
  }, ids) {
    return new Promise((resolve, reject) => {
      deleteHospitalType(ids).then(response => {
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }


}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
